import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {HttpClient} from "@angular/common/http";

@Component({
  selector: 'app-edit-user',
  templateUrl: './edit-user.component.html',
  styleUrls: ['./edit-user.component.css']
})
export class EditUserComponent implements OnInit {
  registerForm: FormGroup;


  constructor(
    private readonly fb: FormBuilder,
    private readonly http: HttpClient
  ) {
    this.registerForm = this.fb.group({
        username: ['', Validators.required],
        name: ['', Validators.required],
        gender: ['', Validators.required],
        phoneNum: ['', Validators.required],
        birthday: ['', Validators.required],
        homeAddress: ['', Validators.required],
        password: ['', [Validators.required, Validators.minLength(6)]],
        confirmPassword: ['', Validators.required],
        isAdmin: [false],
        acceptTerms: [false, Validators.requiredTrue]
      },
      {
        //validator mustMatch("password","confirmPassword")
      }
    )
  }

  genderOpts = [{label: 'Male', value: 1},
    {label: 'Female', value: 2},
    {label: 'Other', value: 3}];

  ngOnInit(): void {

  }

  get f() {
    return this.registerForm.controls;
  }

  onSubmit() {
    if (this.registerForm.validator) {

      return;
    }
    alert(JSON.stringify(this.registerForm.value))
    //this.http.post('/user', this.registerForm.value).subscribe(result => alert(result));

  }

  onReset() {

  }
}
// export function mustMatch(password:string,confirmPassword:string){
//
//   return (formGroup:FormGroup=>const c = this(password)
// const ci
//   if(){}
// if (c==ci){return null}
// else{return ci.must.Error}
// );
//
// }
